//
//  DessertDetailTableViewCell.m
//  吃货·上海
//
//  Created by lanou on 15/11/27.
//  Copyright © 2015年 濮亚军. All rights reserved.
//

#import "DessertDetailTableViewCell.h"
#import "UIImageView+WebCache.h"
@implementation DessertDetailTableViewCell


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        //    菜谱图片
        self.bgView = [[BgView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenWidth) url:self.model.path];
       
       
        
        [self.contentView addSubview:_bgView];
        
        
        //    作者
        CGFloat lableY = self.bgView.frame.size.height + 10;
        self.avatar = [[UIImageView alloc]initWithFrame:CGRectMake(20, lableY, 50, 50)];
        self.avatar.layer.cornerRadius = 25;
        self.avatar.layer.masksToBounds = YES;
//        [self.avatar sd_setImageWithURL:[NSURL URLWithString:self.model.avatar]];
        [self.contentView addSubview:_avatar];
        
        self.nameLable = [[UILabel alloc]initWithFrame:CGRectMake(self.avatar.frame.size.width + 40, lableY, self.contentView.frame.size.width - 100, 50)];
//        self.nameLable.text = self.model.username;
        [self.contentView addSubview:_nameLable];
        
        //    添加一条横线
        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(0, lableY + 60, KScreenWidth, 1)];
        line.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:line];
        
        
        
        //    美食详情
        CGFloat detailHeight = KScreenHeight - self.bgView.frame.size.height - 154;
        self.detail = [[UILabel alloc]initWithFrame:CGRectMake(10, lableY + 70, KScreenWidth - 20, detailHeight )];
//        self.detail.backgroundColor = [UIColor cyanColor];
        self.detail.numberOfLines = 0;
        self.detail.font = [UIFont systemFontOfSize:14];
//        self.detail.text = self.model.msg;
        [self.contentView addSubview:_detail];
        
        
        
    }
    return self;
}

- (void)setModel:(DessertModel *)model

{
    _model = model;
    [self.avatar sd_setImageWithURL:[NSURL URLWithString:self.model.avatar]];
    self.nameLable.text = self.model.username;
    self.detail.text = self.model.msg;
    [self.bgView.icon sd_setImageWithURL:[NSURL URLWithString:model.path] placeholderImage:nil completed:nil];
    
    CGRect bounds = [self.model.msg boundingRectWithSize:CGSizeMake(KScreenWidth - 20, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName] context:nil];
    self.detail.frame = CGRectMake(10, self.detail.frame.origin.y, KScreenWidth - 20, bounds.size.height + 10);
    
}


+ (CGFloat)heightForCell:(DessertModel *)model
{
    CGRect bounds = [model.msg boundingRectWithSize:CGSizeMake(KScreenWidth - 20, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName] context:nil];
    return bounds.size.height + KScreenWidth + 80 + 50;
  
}


@end
